//碰撞 + 摩擦

var iSpeedX = 0;
var iSpeedY = 0;
var lastSpeedY = 0;			//检测停止用

function doMove(obj){
	clearInterval(obj.timer);

	var yMax = document.documentElement.clientHeight - obj.offsetHeight;
	var xMax = document.documentElement.clientWidth - obj.offsetWidth;

	obj.timer = setInterval(function (){
		iSpeedY += 4;

		var x = obj.offsetLeft + iSpeedX;
		var y = obj.offsetTop + iSpeedY;

		if (x > xMax) {				//以下执行的标准时，每次碰到墙壁就减速运动，乘以0.8
			iSpeedX *= -0.8;
			x = xMax;				//使其一瞬间不会有滚动条出现碰撞，下同
		} else if(x < 0){
			iSpeedX *= -0.8;
			x = 0;
		};

		if (y > yMax) {
			iSpeedY *= -0.8;
			iSpeedX *= 0.8;
			y = yMax;
		} else if(y < 0){
			iSpeedY *= -0.8;
			y = 0;
		};

		obj.style.left = x + 'px';
		obj.style.top = y + 'px';

		//检测停止
		if (Math.abs(iSpeedY - lastSpeedY) < 0.5 && Math.abs(iSpeedX) < 1) {//让当前的速度iSpeedY和上一个速度lastY相比,加上ispeedX是为了更加严谨，更加理想
			clearInterval(obj.timer);
		};

		lastSpeedY = iSpeedY;			//判断完是否停止再在最后更新赋值

	},30);
}